home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / fl_rounded_box.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.9 KB  |  98 lines

  1. //
  2. // "$Id: fl_rounded_box.cxx,v 1.4 1999/01/07 19:17:41 mike Exp $"
  3. //
  4. // Rounded box drawing routines for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <FL/Fl.H>
  27. #include <FL/fl_draw.H>
  28.  
  29. #define RN    5
  30. #define RS    15
  31. #define BW    3
  32.  
  33. static double offset[RN] = { 0.0, 0.07612, 0.29289, 0.61732, 1.0};
  34.  
  35. static void rbox(int fill, int x, int y, int w, int h) {
  36.   int i;
  37.   int rsx ,rsy, rs;
  38.   rsx = w*2/5; rsy = h*2/5;
  39.   if (rsx > rsy) rs = rsy; else  rs = rsx;
  40.   if (rs > RS) rs = RS;
  41.   rsx = rs; rsy = rs;
  42.  
  43.   if (fill) fl_begin_polygon(); else fl_begin_loop();
  44.   for (i=0; i<RN; i++)
  45.     fl_vertex(x + offset[RN-i-1]*rsx, y + offset[i] * rsy);
  46.   for (i=0; i<RN; i++)
  47.     fl_vertex(x + offset[i]*rsx, y + h-1 - offset[RN-i-1] * rsy);
  48.   for (i=0; i<RN; i++)
  49.     fl_vertex(x + w-1 - offset[RN-i-1]*rsx, y + h-1 - offset[i] * rsy);
  50.   for (i=0; i<RN; i++)
  51.     fl_vertex(x + w-1 - offset[i]*rsx, y + offset[RN-i-1] * rsy);
  52.   if (fill) fl_end_polygon(); else fl_end_loop();
  53. }
  54.  
  55. static void fl_rflat_box(int x, int y, int w, int h, Fl_Color c) {
  56.   fl_color(c); rbox(1, x, y, w, h); rbox(0, x, y, w, h);
  57. }
  58.  
  59. static void fl_rounded_frame(int x, int y, int w, int h, Fl_Color c) {
  60.   fl_color(c); rbox(0, x, y, w, h);
  61. }
  62.  
  63. static void fl_rounded_box(int x, int y, int w, int h, Fl_Color c) {
  64.   fl_color(c); rbox(1, x, y, w, h);
  65.   fl_color(FL_BLACK); rbox(0, x, y, w, h);
  66. }
  67.  
  68. static void fl_rshadow_box(int x, int y, int w, int h, Fl_Color c) {
  69.   // draw shadow:
  70.   fl_color(FL_DARK3);
  71.   rbox(1, x+BW, y+BW, w, h);
  72.   rbox(0, x+BW, y+BW, w, h);
  73.   // draw the box:
  74.   fl_rounded_box(x, y, w, h, c);
  75. }
  76.  
  77. extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
  78.  
  79. Fl_Boxtype define_FL_ROUNDED_BOX() {
  80.   fl_internal_boxtype(_FL_ROUNDED_FRAME, fl_rounded_frame);
  81.   fl_internal_boxtype(_FL_ROUNDED_BOX, fl_rounded_box);
  82.   return _FL_ROUNDED_BOX;
  83. }
  84.  
  85. Fl_Boxtype define_FL_RFLAT_BOX() {
  86.   fl_internal_boxtype(_FL_RFLAT_BOX, fl_rflat_box);
  87.   return _FL_RFLAT_BOX;
  88. }
  89.  
  90. Fl_Boxtype define_FL_RSHADOW_BOX() {
  91.   fl_internal_boxtype(_FL_RSHADOW_BOX, fl_rshadow_box);
  92.   return _FL_RSHADOW_BOX;
  93. }
  94.  
  95. //
  96. // End of "$Id: fl_rounded_box.cxx,v 1.4 1999/01/07 19:17:41 mike Exp $".
  97. //
  98.